package com.tinem.platform.web.gateway.util;

import cn.hutool.core.util.NumberUtil;
import com.tinem.platform.module.pojo.co.GatewayHeadName;
import org.springframework.web.server.ServerWebExchange;

/**
 * @author fzh
 * @version v1
 * @program: platform
 * @className GatewayUtil
 * @description TODO
 * @site 
 * @company 
 * @create 2020-09-29 16:10
 */
@SuppressWarnings("unchecked")
public class GatewayUtil {

    public static Long getReqTimestamp(ServerWebExchange exchange) {
        return NumberUtil.parseLong(exchange.getRequest().getQueryParams().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_URL_TIMESTAMP));
    }

    public static String getApiReq(ServerWebExchange exchange) {
        return exchange.getRequest().getHeaders().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_REQ_API_REQUEST_ID);
    }

    public static String getJwt(ServerWebExchange exchange) {
        return exchange.getRequest().getHeaders().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_REQ_JWT);
    }
    public static String getApiService(ServerWebExchange exchange) {
        return exchange.getRequest().getHeaders().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_REQ_SERVICE);
    }
    public static String getApiMethod(ServerWebExchange exchange) {
        return exchange.getRequest().getHeaders().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_REQ_METHOD);
    }
    public static String getClientReqSign(ServerWebExchange exchange){
        return exchange.getRequest().getHeaders().getFirst(GatewayHeadName.X_PLATFORM_GATEWAY_REQ_SIGN);
    }

    public static String getReq(ServerWebExchange exchange) {
        return exchange.getAttribute(GatewayHeadName.X_PLATFORM_GATEWAY_REQUEST_ID);
    }
    public static String getJit(ServerWebExchange exchange) {
        return exchange.getAttribute(GatewayHeadName.X_PLATFORM_GATEWAY_CONTEXT_JTI);
    }
    public static String getClient(ServerWebExchange exchange) {
        return exchange.getAttribute(GatewayHeadName.X_PLATFORM_GATEWAY_CONTEXT_CLIENT_ID);
    }
    public static Long getReqAcceptTimestamp(ServerWebExchange exchange) {
        return exchange.getAttribute(GatewayHeadName.X_PLATFORM_GATEWAY_CONTEXT_ACCEPT_TIMESTAMP);
    }
}
